public class of04 {
    public static void main(String[] args) {
        
    }
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        int n=matrix.length;
        int m=matrix[0].length;
        for(int i=0;i<n&&i>=0;){
            for(int j=m-1;j>=0&&j<m;){
                if(matrix[i][j]==target){
                    return true;
                }
                if(i==n-1&&j==0){
                    if(matrix[i][j]!=target){
                        return false;
                    }
                }else if(i==n-1){
                    j--;
                }else if(j==0){
                    i++;
                }else if(matrix[i][j-1]>target){
                    j--;
                }else if(matrix[i][j]<target){
                    i++;
                }
                if(matrix[i][j]==target){
                    return true;
                }
            }
        }
    }
}
